package com.video.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoCommodity;
import com.video.system.service.IVideoCommodityService;
import com.video.common.utils.poi.ExcelUtil;

/**
 * 商品管理Controller
 * 
 * @author lyh
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/system/commodity")
public class VideoCommodityController extends BaseController
{
    @Autowired
    private IVideoCommodityService videoCommodityService;

    /**
     * 查询商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:list')")
    @GetMapping("/list")
    public AjaxResult list(VideoCommodity videoCommodity)
    {
        List<VideoCommodity> list = videoCommodityService.selectVideoCommodityList(videoCommodity);
        return AjaxResult.success(list);
    }

    /**
     * 导出商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:export')")
    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoCommodity videoCommodity)
    {
        List<VideoCommodity> list = videoCommodityService.selectVideoCommodityList(videoCommodity);
        ExcelUtil<VideoCommodity> util = new ExcelUtil<VideoCommodity>(VideoCommodity.class);
        return util.exportExcel(list, "商品管理数据");
    }

    /**
     * 获取商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:query')")
    @GetMapping(value = "/{commodityId}")
    public AjaxResult getInfo(@PathVariable("commodityId") Integer commodityId)
    {
        return AjaxResult.success(videoCommodityService.selectVideoCommodityById(commodityId));
    }

    /**
     * 新增商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:add')")
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoCommodity videoCommodity)
    {
        return toAjax(videoCommodityService.insertVideoCommodity(videoCommodity));
    }

    /**
     * 修改商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:edit')")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoCommodity videoCommodity)
    {
        return toAjax(videoCommodityService.updateVideoCommodity(videoCommodity));
    }

    /**
     * 删除商品管理
     */
    @PreAuthorize("@ss.hasPermi('system:commodity:remove')")
    @Log(title = "商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commodityIds}")
    public AjaxResult remove(@PathVariable Integer[] commodityIds)
    {
        return toAjax(videoCommodityService.deleteVideoCommodityByIds(commodityIds));
    }
}
